package app 
{
	import fl.video.FLVPlayback;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import utils.Logger;
	/**
	 * ...
	 * @author Dmitriy Gaiduk
	 */
	public class TutorModule extends Sprite
	{
		private var _flvPlayer:FLVPlayback;
		private var _visual:Sprite;
		private var _videoUrl:String;
		
		public function TutorModule(url:String) 
		{
			
			_videoUrl = url;
			initComponent();
		}
		
		private function initComponent():void 
		{
			_visual = new VideoPlayerMov();
			addChild(_visual);
			
			_flvPlayer = _visual.getChildByName("flv") as FLVPlayback;
			if (_flvPlayer == null) {
				log("flv null");
				return;
			}
			
			_flvPlayer.source = _videoUrl;
			
			var _closeButton:SimpleButton = _visual.getChildByName("closeBtn") as SimpleButton;
			if (_closeButton == null) {
				log("closeButton null");
				return;
			}
			
			_closeButton.addEventListener(MouseEvent.CLICK, handleCloseClick);
			
		}
		
		private function handleCloseClick(e:MouseEvent):void 
		{
			stopVideo();
			if (this.parent != null) {
				this.parent.removeChild(this);
			}
		}
		
		public function stopVideo():void {
			if (_flvPlayer != null) {
				try {
					_flvPlayer.stop();
				}catch (e:Error) {
					log("Error: " + e.message);
				}
				
			}
		}
		
		private function log(msg:String):void {
			Logger.log(this, msg);
		}
		
	}

}